<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">

    <script type="text/javascript">
      //从 file 域获取 本地图片 url
      function getFileUrl(sourceId) {
        var url
        if (navigator.userAgent.indexOf('MSIE') >= 1) { // IE
          url = document.getElementById(sourceId).value
        } else if (navigator.userAgent.indexOf('Firefox') > 0) { // Firefox
          url = window.URL.createObjectURL(document.getElementById(sourceId)
            .files
            .item(0))
        } else if (navigator.userAgent.indexOf('Chrome') > 0) { // Chrome
          url = window.URL.createObjectURL(document.getElementById(sourceId)
            .files
            .item(0))
        }
        return url
      }

      //将本地图片 显示到浏览器上
      function preImg(sourceId, targetId) {
        var url = getFileUrl(sourceId)
        var imgPre = document.getElementById(targetId)
        imgPre.src = url

        if (imgPre.fileSize > 0 || (imgPre.width > 0 && imgPre.height > 0)) {
          return true
        } else {
          return false
        }
//            if (imgPre.files && imgPre.files[0]) {
//               imgPre.removeAttr("hidden");
//            }else{
//                imgPre.attr("hidden","hidden");
//            }
      }

      function isHasImg() {
        var ImgObj = document.getElementById()
        ImgObj.src = pathImg
        if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
          return true
        } else {
          return false
        }
      }


    </script>
    <title>商品上架页面</title>

    <link rel="stylesheet" href="../extra.css">
    <!-- Font Awesome Icons -->
    <link rel="stylesheet" href="../../../plugins/font-awesome/css/font-awesome.min.css">
    <!-- IonIcons -->
    <link rel="stylesheet" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../../../dist/css/adminlte.min.css">
    <!-- Google Font: Source Sans Pro -->
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to to the body tag
to get the desired effect
|---------------------------------------------------------|
|LAYOUT OPTIONS | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body class="hold-transition sidebar-mini">
<div class="wrapper">
    <!-- Navbar -->
    <nav class="main-header navbar navbar-expand bg-white navbar-light border-bottom">
        <!-- Left navbar links -->
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" data-widget="pushmenu" href="#"><i class="fa fa-bars"></i></a>
            </li>
            <li class="nav-item d-none d-sm-inline-block">
                <a href="index.html" class="nav-link">主页</a>
            </li>
            <li class="nav-item d-none d-sm-inline-block">
                <a href="#" class="nav-link">联系</a>
            </li>
        </ul>

        <!-- SEARCH FORM -->
        <form class="form-inline ml-3">
            <div class="input-group input-group-sm">
                <input class="form-control form-control-navbar" type="search" placeholder="搜索" aria-label="Search">
                <div class="input-group-append">
                    <button class="btn btn-navbar" type="submit">
                        <i class="fa fa-search"></i>
                    </button>
                </div>
            </div>
        </form>


        <!-- Right navbar links -->
        <ul class="navbar-nav ml-auto">
            <!-- Messages Dropdown Menu -->
            <!--<li class="nav-item dropdown">-->

            <li class="nav-item">
                <button style="font-weight: bold" type="button" class="button-pill button button-caution"
                        onclick="logout()">
                    退出
                </button>
            </li>

            <li class="nav-item">
                <a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#"><i
                        class="fa fa-th-large"></i></a>
            </li>
        </ul>
    </nav>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->
    <aside class="main-sidebar sidebar-dark-primary elevation-4">
        <!-- Brand Logo -->
        <!--<a href="index3.html" class="brand-link">-->
        <!--<img src="dist/img/AdminLTELogo.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3"-->
        <!--style="opacity: .8">-->
        <!--<span class="brand-text font-weight-light">AdminLTE 3</span>-->
        <!--</a>-->

        <!-- Sidebar -->
        <div class="sidebar">
            <!-- Sidebar user panel (optional) -->
            <div class="user-panel mt-3 pb-3 mb-3 d-flex">
                <div class="image">
                    <img src="../../../dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image">
                </div>
                <div class="info">
                    <a href="#" class="d-block">用户</a>
                </div>
            </div>

            <!-- Sidebar Menu -->
            <nav class="mt-2">
                <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu"
                    data-accordion="false">
                    <!-- Add icons to the links using the .nav-icon class
                         with font-awesome or any other icon font library -->
                    <li class="nav-item ">
                        <a href="index.html" class="nav-link">
                            <i class="nav-icon fa fa-dashboard"></i>
                            <p>
                                案件概况
                                <!--<i class="right fa fa-angle-left"></i>-->
                            </p>
                        </a>
                    </li>



                    <li class="nav-item has-treeview">
                        <a href="case.html" class="nav-link active">
                            <i class="nav-icon fa fa-table"></i>
                            <p>
                                案件管理
                                <!--<i class="fa fa-angle-left right"></i>-->
                            </p>
                        </a>
                    </li>

                    <li class="nav-item has-treeview">
                        <a href="#" class="nav-link">
                            <i class="nav-icon fa fa-table"></i>
                            <p>
                                协查表管理
                                <i class="fa fa-angle-left right"></i>
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="assistant.html" class="nav-link">
                                    <i class="fa fa-circle-o nav-icon"></i>
                                    <p>协查表信息</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="feedback.html" class="nav-link">
                                    <i class="fa fa-circle-o nav-icon"></i>
                                    <p>反馈信息</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </nav>
            <!-- /.sidebar-menu -->
        </div>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0 text-dark">案件信息添加</h1>
                    </div><!-- /.col -->
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item">主页</a></li>
                            <li class="breadcrumb-item active">案件管理</li>
                        </ol>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->

        </div>
        <!-- /.content-header -->

        <section class="content">
            <div class="row">

                <div class="col-2">

                </div>
                <div class="col-8">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card card-default">
                                <div class="card-header">
                                    <h3 class="card-title"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">案件相关图片</font></font></h3>
                                </div>
                                <div class="card-body">
                                    <div id="actions" class="row">
                                        <div class="col-lg-6">
                                            <div class="btn-group w-100">
                      <span class="btn btn-success col fileinput-button dz-clickable">
<!--                        <i class="fas fa-plus"></i>-->
                        <span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">添加文件</font></font></span>
                      </span>
                                                <button type="submit" class="btn btn-primary col start">
                                                    <!--                                                    <i class="fas fa-upload"></i>-->
                                                    <span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">开始上传</font></font></span>
                                                </button>
                                                <button type="reset" class="btn btn-warning col cancel">
                                                    <!--                                                    <i class="fas fa-times-circle"></i>-->
                                                    <span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">取消上传</font></font></span>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="col-lg-6 d-flex align-items-center">
                                            <div class="fileupload-process w-100">
                                                <div id="total-progress" class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
                                                    <div class="progress-bar progress-bar-success" style="width: 100%;" data-dz-uploadprogress=""></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="table table-striped files" id="previews">

                                    </div>
                                </div>
                                <!-- /.card-body -->
                                <!--                                <div class="card-footer"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">有关插件的更多示例和信息，请</font><font style="vertical-align: inherit;">-->
                                <!--                                    访问</font></font><a href="https://www.dropzonejs.com"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">dropzone.js 文档</font></font></a><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">。-->
                                <!--                                </font></font></div>-->
                            </div>
                            <!-- /.card -->
                        </div>
                    </div>




                    <div class="card card-primary">
                        <div class="card-header">
                            <h3 class="card-title">案件信息填写</h3>
                        </div>
                        <!-- /.card-header -->
                        <!-- form start -->
                        <!--data-inputmask="'alias': 'dd/mm/yyyy'" data-mask-->
                        <form role="form">
                            <div class="card-body">

                                <div class="form-group">
                                    <label for="casename">案件名 <font color="red">*</font></label>
                                    <input type="text" class="form-control" id="casename"
                                           placeholder="输入案件名">
                                </div>
                                <div class="form-group">
                                    <label for="numbers">案件编号 <font color="red">*</font></label>
                                    <input type="text" class="form-control" id="numbers"
                                           placeholder="输入案件编号" >
                                </div>
                                <div class="form-group">
                                    <label for="casetype_id">案件类别 <font color="red">*</font></label>
                                    <select class="form-control" id="casetype_id" >
                                        <option value="0">请选择</option>
                                        <option value="1">刑事案件</option>
                                        <option value="2">行政案件</option>
                                        <option value="3">案事件初查</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label >罪名种类<font color="red">*</font></label>
                                    <select class="form-control" id="accusationtype_id" >
                                        <option value="0">请选择</option>
                                        <option value="1">诈骗类</option>
                                        <option value="2">伤害类</option>
                                        <option value="3">毒品类</option>
                                        <option value="4">色情类</option>
                                        <option value="5">国家安全类</option>
                                        <option value="6">其他</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="intendeds">文书号 <font color="red">*</font></label>
                                    <input type="text" class="form-control" id="writid"
                                           placeholder="文书号">
                                </div>
<!--                                <div class="form-group">-->
<!--                                    <label for="tel">联系方式 <font color="red">*</font></label>-->
<!--                                    <input type="text" class="form-control" id="tel"-->
<!--                                           placeholder="输入联系方式">-->
<!--                                </div>-->

                                <div class="form-group">
                                    <label>基本情况<font color="red">*</font></label>
                                    <textarea class="form-control" rows="3" placeholder="输入基本情况"
                                              id="detail"></textarea>
                                </div>
                                <div class="callout callout-info">
                                    <h5>案件信息填写提示</h5>

                                    <p>带*为必填字段，其余可选填.</p>
                                </div>
                            </div>
                        </form>

                    </div>

                    <center>
                        <div class="button-group" style="margin:10px auto">
                            <button type="button" class="button button-pill button-lg button-action"
                                    onclick="addGoods()">提交
                            </button>
<!--                            <button type="button" class="button button-pill button-lg button-primary" onclick="reset()">-->
<!--                                重置-->
<!--                            </button>-->
                            <button type="button" class="button button-pill button-lg button-caution"
                                    onclick="location='case.html'">取消
                            </button>
                        </div>
                    </center>

                </div>
                <div class="col-2">
                </div>

            </div>
            <!--&lt;!&ndash; /.row &ndash;&gt;-->
        </section>

    </div>
    <!-- /.content -->
    <!-- /.content-wrapper -->

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Control sidebar content goes here -->
    </aside>
    <!-- /.control-sidebar -->

    <!-- Main Footer -->
    <footer class="main-footer">
        <!-- To the right -->
        <div class="float-right d-none d-sm-block-down">
            Anything you want
        </div>
        <!-- Default to the left -->
        <strong>Copyright &copy; 2018 Solitary.</strong> All rights reserved.
    </footer>
</div>
<!-- ./wrapper -->
<div style="display:none">
    <div id="template" class="row mt-2 dz-image-preview">
        <div class="col-auto">
            <span class="preview"><img src="" alt="" data-dz-thumbnail=""></span>
        </div>
        <div class="col d-flex align-items-center">
            <p class="mb-0">
                <span class="lead" data-dz-name="">笔录1.jpg</span>
                (<span data-dz-size=""><strong>0.3</strong> MB</span>)
            </p>
            <strong class="error text-danger" data-dz-errormessage=""></strong>
        </div>
        <div class="col-4 d-flex align-items-center">
            <div class="progress progress-striped active w-100" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
                <div class="progress-bar progress-bar-success" style="width:0%;" data-dz-uploadprogress=""></div>

            </div>
        </div>
        <div class="col-auto d-flex align-items-center">
            <div class="btn-group">
                <button class="btn btn-primary start">
                    <span>开始上传</span>
                </button>
                <button data-dz-remove="" class="btn btn-warning cancel">

                    <span>取消上传</span>
                </button>
                <button data-dz-remove="" class="btn btn-danger delete">

                    <span>删除文件</span>
                </button>
            </div>
        </div>
    </div>
</div>
<!-- REQUIRED SCRIPTS -->

<!-- jQuery -->
<script src="../../../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="../../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE -->
<script src="../../../dist/js/plugins/dropzone/dropzone.min.js"></script>
<script src="../../../dist/js/adminlte.js"></script>

<!-- OPTIONAL SCRIPTS -->
<script src="../../../plugins/chart.js/Chart.min.js"></script>
<script src="../../../dist/js/demo.js"></script>
<script src="../../../dist/js/pages/dashboard3.js"></script>
<script>
;
  var user_token = sessionStorage.getItem('user_token');
  let case_id = sessionStorage.getItem('case_id');
  let area_id = sessionStorage.getItem('area_id');
  var picurl="";
  console.log(area_id)

  $(function () {
      if (case_id!=null){
          renderShopSelect()
      }else {
          return;
      }

      // DropzoneJS演示代码开始
      Dropzone.autoDiscover = false

      // 获取模板HTML并将其从文档中移除
      var previewNode = document.querySelector("#template")
      previewNode.id = ""
      var previewTemplate = previewNode.parentNode.innerHTML
      previewNode.parentNode.removeChild(previewNode)
      var index = 0;
      var myDropzone = new Dropzone(document.body, { // Make the whole body a dropzone
          url: "http://localhost:5744/api/images/fileUpload", // Set the url
          thumbnailWidth: 80,
          paramName: "file",
          method:"POST",
          headers: {
              'Authorization': user_token
          },
          processData: false,
          contentType: false,
          maxFiles: 1,
          acceptedFiles: ".jpg,.gif,.png,.jpeg,.pdf",
          dictMaxFilesExceeded: "您最多只能上传1个文件！",
          dictResponseError: '文件上传失败!',
          dictInvalidFileType: "文件类型只能是*.jpg,*.gif,*.png,*.jpeg。",
          dictFallbackMessage: "浏览器不受支持",
          thumbnailHeight: 80,
          parallelUploads: 1,
          previewTemplate: previewTemplate,
          autoQueue: false, // Make sure the files aren't queued until manually added
          previewsContainer: "#previews", // Define the container to display the previews
          clickable: ".fileinput-button" ,// Define the element that should be used as click trigger to select files.
          init: function() {
              //上传文件时触发的事件
              this.on("addedfile", function(file) {
                  //浏览器控制台输出js
                  console.log("File " + file.name + "uploaded");
              });
              //上传文件成功时触发的事件
              this.on("success", function(file) {

                  var result = JSON.parse(file.xhr.response);
                  picurl=result.data;
                  console.log("File: " + picurl);

              });
              //移除文件触发的事件
              this.on("removedfile", function(file) {
                  console.log("File " + file.name + "removed");
              });
          }
      })

      myDropzone.on("addedfile", function (file) {
          // 连接开始按钮
          file.previewElement.querySelector(".start").onclick = function () {
              myDropzone.enqueueFile(file)
          }
      })

      // 更新总进度条
      myDropzone.on("totaluploadprogress", function (progress) {
          document.querySelector("#total-progress .progress-bar").style.width = progress + "%"
      })

      myDropzone.on("sending", function (file) {
          // 上传开始时显示总进度条
          document.querySelector("#total-progress").style.opacity = "1"
          // 禁用开始按钮
          file.previewElement.querySelector(".start").setAttribute("disabled", "disabled")
      })

      // 当没有东西上传时隐藏总进度条
      myDropzone.on("queuecomplete", function (progress) {
          document.querySelector("#total-progress").style.opacity = "0"
      })

      // 设置所有传输的按钮
      // “添加文件”按钮不需要设置，因为配置
      // ' clickable '已经被指定。
      document.querySelector("#actions .start").onclick = function () {
          myDropzone.enqueueFiles(myDropzone.getFilesWithStatus(Dropzone.ADDED))
      }
      document.querySelector("#actions .cancel").onclick = function () {
          myDropzone.removeAllFiles(true)
      }
      //DropzoneJS演示代码结束
  })

function renderShopSelect() {
    var case_id = sessionStorage.getItem('case_id')

    var settings = {
        'async': true,
        'crossDomain': true,
        'url': 'http://127.0.0.1:5744/api/case/selcet/' + case_id,
        'method': 'GET',
        'headers': {
            'Authorization': user_token
        }
    }


    $.ajax(settings)
        .done(function (response) {
            console.log(response)
            if (response.code == 0) {
                let data = response.data
                $('#casename')
                    .val(data.casename)
                $('#numbers')
                    .val(data.numbers)
                $('#casetype_id')
                    .val(data.casetype_id)
                $('#accusationtype_id')
                    .val(data.intendeds)
                $('#writid')
                    .val(data.writid)
                $('#detail')
                    .val(data.basic)


            } else {
                console.log(response.message)
            }
        })

}




  function addGoods() {
      let form = new FormData()
      let  casename = $('#casename')
          .val()
      let  numbers = $('#numbers')
          .val()
      let  casetype_id = $('#casetype_id')
          .val()
      let  writid = $('#writid')
          .val()
      let  accusationtype_id = $('#accusationtype_id')
          .val()
      let  detail = $('#detail')
          .val()
      form.append('casename', casename)
      form.append('area_id', area_id)
      form.append('numbers', numbers)
      form.append('casetype_id',casetype_id)
      form.append('writid', writid)
      form.append('picpath', picurl)
      form.append('crimetypes', accusationtype_id)
      form.append('detail', detail)


            const settings = {
                'async': true,
                'crossDomain': true,
                'url': 'http://localhost:5744/api/case/update/'+ case_id,
                'method': 'POST',
                'headers': {
                    'Authorization': user_token
                },
                'processData': false,
                'contentType': false,
                'mimeType': 'multipart/form-data',
                'data': form
            }
            $.ajax(settings)
                .done(function (response) {
                    response = JSON.parse(response)
                    if (response.code == 0) {
                        alert(response.message)
                        // $('#login-form').attr('action', '../admin/index.html')
                        window.location.href = 'case.html'

                    } else {
                        alert(response.message)
                    }
                })


  }



  function isnull(val) {
    var str = val.replace(/(^\s*)|(\s*$)/g, '')//去除空格;

    if (str == '' || str == undefined || str == null) {
      //return true;
      console.log('空')
    } else {
      //return false;
      console.log('非空')
    }
  }

  function logout() {
    sessionStorage.removeItem('user_token')
    window.location.href = '../common/login.html'

  }


</script>
</body>
</html>
